package com.ruoyi.web.controller.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.xs.XsOrderSource;
import com.ruoyi.system.service.IXsOrderSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单来源Controller
 *
 * @author ruoyi
 * @date 2025-01-13
 */
@RestController
@RequestMapping("/system/source")
public class XsOrderSourceController extends BaseController {
    @Autowired
    private IXsOrderSourceService xsOrderSourceService;

    /**
     * 查询订单来源列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XsOrderSource xsOrderSource) {
        startPage();
        List<XsOrderSource> list = xsOrderSourceService.selectXsOrderSourceList(xsOrderSource);
        return getDataTable(list);
    }

    /**
     * 导出订单来源列表
     */
    @Log(title = "订单来源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XsOrderSource xsOrderSource) {
        List<XsOrderSource> list = xsOrderSourceService.selectXsOrderSourceList(xsOrderSource);
        ExcelUtil<XsOrderSource> util = new ExcelUtil<XsOrderSource>(XsOrderSource.class);
        util.exportExcel(response, list, "订单来源数据");
    }

    /**
     * 获取订单来源详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xsOrderSourceService.selectXsOrderSourceById(id));
    }

    /**
     * 新增订单来源
     */
    @Log(title = "订单来源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XsOrderSource xsOrderSource) {
        return toAjax(xsOrderSourceService.insertXsOrderSource(xsOrderSource));
    }

    /**
     * 修改订单来源
     */
    @Log(title = "订单来源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XsOrderSource xsOrderSource) {
        return toAjax(xsOrderSourceService.updateXsOrderSource(xsOrderSource));
    }

    /**
     * 删除订单来源
     */
    @Log(title = "订单来源", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xsOrderSourceService.deleteXsOrderSourceByIds(ids));
    }
}
